<?
//Initiate Authenticate
SecurityRedirect ();

//initiate Vars
define("PRIMARY_KEY","nobkt");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_memo_thirteenth.php";
$FileTemplate  = "ais_transaction_memo_thirteenth_list.html";
$TableName     = "ais_memorial";
$SubHeaderTitle= "Transaction Memorial - Thirteenth Month Transaction";
$PageSize      = 10 ;
$HTMLGridList  = "MemorialGrid";

//************ FORM ACTION **************
if (GetParam("Action","")=="Delete") {
        DeleteRecord ("txtCheck",$PageSize);
}

//Initiate Database Table For Search;
$FCode = GetParam("nomemoestSearch","");
$QueryGet  = GetQueryString("All", array('PageNum'));

//******* DATABASE FORM QUERY ***********

//butuh nampilin jumlah ga ya, kalo butuh, tambahin amount
$SQL = "SELECT *, sum(if(dk='D',jumlah,0)) as jumlah FROM `$TableName` ";
$SQLCount = "SELECT count(*) FROM `$TableName` ";
$WHERE = " nobkt REGEXP '^MM[0-9]{2}13'";
$WHERE .= " AND ".QueryLedger();

//Retrieve Parameter from search

if ($FCode) {
    $CustomWhere = " nobkt like '".$FCode."%'";
    if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
    else $WHERE = $CustomWhere;
}

if (strlen($WHERE)) {
    $SQL = $SQL."WHERE ".$WHERE;
}
else $SQL = $SQL;

$SQL .= " GROUP BY nobkt";
$SQL .= " ORDER BY tglbkt DESC, nobkt DESC";

//******* SHOW FORM CONTENT *********

$PageNum = 1;

if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

//Default value
if (!isset($_GET)) $_GET=&$HTTP_GET_VARS ;
if (isset($_GET['PageNum'])) {
  $PageNum = $_GET['PageNum'] ;
} else {
    $PageNum = 1 ;
}

//Default value
if (isset($_GET['RecCnt'])) {
  $RecCnt = intval($_GET['RecCnt']) ;
} else {
    $RecCnt = -1 ;
}

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$RecCnt = $TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize) ;
$TBS->Show();

function DeleteRecord ($sequence_name,$PageSize) {
    global $DBConnection,$FileName,$TableName;
    for ($x=1;$x<=$PageSize;$x++) {
        if (GetParam($sequence_name.$x,"")) {
            $DBConnection->Delete("$TableName",$sequence_name.$x);
        }
    }
    header("Location: $FileName");
    exit;

}

?>
